package net.csdn.business.discuss.api.controller;


import com.alibaba.fastjson2.JSON;
import lombok.extern.slf4j.Slf4j;
import net.csdn.business.discuss.api.facade.DiscussWrapperFacade;
import net.csdn.business.discuss.api.model.dto.DeleteResourceDTO;
import net.csdn.business.discuss.api.model.dto.NewDiscussSectionDTO;
import net.csdn.business.discuss.api.model.dto.UpdateAuditStatusDTO;
import net.csdn.business.discuss.api.model.dto.UpdateDiscussSectionDTO;
import net.csdn.business.discuss.api.model.vo.DiscussSectionVO;
import net.csdn.business.discuss.api.service.IDiscussSectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @ClassName DiscussSectionController
 * @Description 讨论类型分组
 * @Author zhangyl
 * @Date 2023/7/15 15:47
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/discuss/section")
public class DiscussSectionController
{
    @Autowired
    private IDiscussSectionService discussSectionService;

    @Autowired
    private DiscussWrapperFacade discussWrapperFacade;

    /**
     * 查询讨论类型分组列表
     */
    @GetMapping("/list/{sourceId}")
    public List<DiscussSectionVO> getListBySourceId(@PathVariable("sourceId")String sourceId)
    {
        return discussSectionService.selectDiscussSectionListBySourceId(sourceId);
    }



    /**
     * 根据id获取讨论类型分组详情
     */
    @GetMapping(value = "/{id}")
    public DiscussSectionVO getInfo(@PathVariable("id") String id)
    {
        return discussSectionService.selectDiscussSectionDetail(id);
    }

    /**
     * 新增讨论类型分组
     */
    @PostMapping
    public String add(@RequestBody @Validated NewDiscussSectionDTO discussSection)
    {
        return discussWrapperFacade.addSection(discussSection);
    }

    /**
     * 修改讨论类型分组
     */
    @PutMapping
    public Integer edit(@RequestBody @Validated UpdateDiscussSectionDTO discussSection)
    {
        return discussWrapperFacade.editSection(discussSection);
    }

    /**
     * 删除讨论类型分组
     */
	@DeleteMapping
    public Integer delete(@RequestBody @Validated DeleteResourceDTO params)
    {
        return discussWrapperFacade.deleteSection(params);
    }

    /**
     * 更新审核状态
     */
    @PostMapping("/updateAuditStatus")
    public Integer updateAuditStatus(@RequestBody @Validated UpdateAuditStatusDTO params){
        log.info("discuss update audit status params:{}", JSON.toJSONString(params));
        return discussSectionService.updateAuditStatus(params);
    }
}
